package com.cyz.web.app.thread.cycleBarrie;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class Demo {

    public static void main(String[] args) {


        CyclicBarrier cyclicBarrier = new CyclicBarrier(20, () -> {
            System.out.println("人到齐开车");
        });

        for (int i = 0; i < 100; i++) {
            new Thread(() -> {
                try {
                    cyclicBarrier.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }).start();
        }

    }


}
